package demo11;

public class Test {
    public String minWindow(String s, String t) {
        char[] ss = s.toCharArray();
        char[] tt = t.toCharArray();
        int[] hash1 = new int[128];
        int kinds = 0;
        for (char ch : tt)
            if (hash1[ch]++ == 0)  kinds++;
        int[] hash2 = new int[128];
        int n = ss.length, minlen = Integer.MAX_VALUE, begin = -1;
        for (int left = 0, right = 0, count = 0; right < n; right++) {
            char in = ss[right];
            //进窗口 维护count
            if (++hash2[in] == hash1[in]) count++;

            while (count == kinds) { //判断
                if (right -left + 1 < minlen) { //更新结果
                    minlen = right - left + 1;
                    begin = left;
                }
                //出窗口 维护count
                char out = ss[left++];
                if (hash2[out]-- == hash1[out]) count--;

            }
        }
        if (begin == -1) return new String();
        else return s.substring(begin, begin + minlen);
    }

    public void moveZeroes(int[] nums) {
        int n = nums.length;
        for (int cur = 0, dest = -1; cur < n; cur++) {
            if (nums[cur] != 0) {
                dest++;
                int tmp = nums[cur];
                nums[cur] = nums[dest];
                nums[dest] = tmp;
            }
        }
    }
}
